********************************************************************************
* Replication file for "Does earmarked funding affect the performance of IOs?"
********************************************************************************

* Data loading
**************

  use "MBIPEF_replication", clear
  

* Plots
*******

* Understanding IO differences 
  
  encode acronym, g(io)
  lab var io "IO"
  
  reg y1 i.newmopan, ro 
  reg y1 i.newmopan i.io, ro
  margins io, atmeans post 
  est store Process_performance
  
  reg y2 i.newmopan i.io, ro
  margins io, atmeans post 
  est store Outcome_performance
  
** Figure 1 **
coefplot Process_performance || Outcome_performance, scheme(s1mono) xtitle(" ") xline(0, lpattern(dot))


* IO funding structures (latest year)

preserve
  g Core=coreST
  replace Core=coreSTd if coreST==.
  egen maxy=max(year), by(acronym)
  keep if year==maxy
  
  collapse (mean)emST_MBI Core, by(acronym)
  replace emST=ln(emST_MBI)
  replace Core=ln(Core)
  
  g pos=3
  replace pos=12 if acro=="UNDP"
  replace pos=9 if acro=="UNICEF"
  replace pos=6 if acro=="FAO"
  replace pos=12 if acro=="WHO"
  replace pos=9 if acro=="UNWOMEN"
  replace pos=6 if acro=="UNEP"
  replace pos=12 if acro=="WFP"
  replace pos=9 if acro=="UNESCO"
  replace pos=9 if acro=="UNFPA"

** Figure 2 **
twoway scatter Core emST_MBI, scheme(s1mono) mlab(acro) mlabv(pos) xtitle(Logged earmarked funding) ytitle(Logged core funding)
restore 


* Earmarking aid and IO performance  
  
  g pos=3
  replace pos=6 if acro=="UNRWA"
  replace pos=12 if acro=="UNICEF" & year==2012
  replace pos=3 if acro=="UNEP" & year==2021
  
** Figure 3 **  
twoway (scatter y1 EMLT, mlab(acr) mlabv(pos) mlabsize(vsmall)) (lfit y1 EMLT), scheme(s1mono) ytitle(Process performance) xtitle(Average earmarking share) legend(off) 
 
  replace pos=3
  replace pos=12 if acro=="UNWOMEN" & year==2014
  replace pos=12 if acro=="UNWOMEN" & year==2017
  replace pos=12 if acro=="UN-HABITAT" & year==2015
  
** Figure 4 **  
twoway (scatter y2 EMLT, mlab(acr) mlabv(pos) mlabsize(vsmall)) (lfit y2 EMLT), scheme(s1mono) ytitle(Outcome performance) xtitle(Average earmarking share) legend(off) 
  

* Figures for appendix

** Figure A1 **  
twoway scatter y2 y1, mlab(acr) mlabsize(vsmall) scheme(s1mono) xtitle(Process performance) ytitle(Outcome performance) xline(0, lpattern(dot)) yline(0, lpattern(dot))

** Figure A2 **  
twoway (scatter y1 EMLT, mlab(acr)) (lfit y1 EMLT), by(un, note( )) scheme(s1mono) ytitle(Process performance) xtitle(Average earmarking share) legend(off)

  
* Main analysis
***************

  encode hq, g(hqid)
  encode ten, g(tenid)
  g tenbig=tenid>=3
  g selectbig=selectorate==3
  g lnsize=ln(coreST+emST)
  g lnstaff=ln(staff_count)
  g fieldshare=(field_pres/staff_count)
  g lnage=ln(2022-founding)
  g hqSouth=hq=="Amman"|hq=="Abidjan"|hq=="Manila"|hq=="Nairobi"
  
  global B tenbig selectbig 
  global C lnsize fieldshare lnsectors lnage hqSouth
  global D normio states_num states_unga_sd 
  
  
* Determinants of PP

  qui reg y1 EMST newmopan, ro
  est store a11
  qui reg y1 EMST newmopan $B, ro
  est store a12
  qui reg y1 EMST newmopan $C, ro
  est store a13
  qui reg y1 EMST newmopan $B $C, ro
  est store a14  

** Table 4 **  
estout a1*, starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_*) stat(N r2, fmt(0 3))

  est restore a11
  su EMST y1 if e(sample)
  margins, at(EMST=(0.494 0.794)) 
  est restore a13
  list acro year y1 EMST lnsize if acro=="WFP"
  margins, at(EMST=(0.919 0.619)) 
  *** is a 0.393 effect **
  margins, at(EMST=(0.619) lnsize=(8.48 4.9))
  
  
* Determinants of PP -- IV/2SLS
  
  qui ivreg2 y1 (EMST=meanwSIM) newmopan, ro first
  est store b11
  qui ivreg2 y1 (EMST=meanwSIM) newmopan $B, ro first
  est store b12
  qui ivreg2 y1 (EMST=meanwSIM) newmopan $C, ro first
  est store b13
  qui ivreg2 y1 (EMST=meanwSIM) newmopan $B $C, ro first
  est store b14

** Table 5 **  
estout b1*, starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_*) stat(N r2 idstat, fmt(0 3 3))
    
  
* Robustness tests
*******************************************************************************

* Descriptive statistics

  qui estpost su y1 y2 EMST EMLT newmopan $B $C emshareLTb meanwSIM   
  
  ** Table A5 **
  esttab ., cells("count mean sd min max")

  
* Outcome performance 

  qui reg y2 EMST newmopan, ro
  est store r11
  qui reg y2 EMST newmopan $B $C, ro
  est store r12
  qui ivreg2 y2 (EMST=meanwSIM) newmopan, ro first
  est store r13
  qui ivreg2 y2 (EMST=meanwSIM) newmopan $B $C, ro first
  est store r14

** Table A6 **
estout r1*, starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_*) stat(N r2 idstat, fmt(0 3 3))
    

* Controlling for IO norm-making functions

  qui reg y1 EMST normio newmopan, ro
  est store r21
  qui reg y1 EMST normio newmopan $B $C, ro
  est store r22
  qui ivreg2 y1 (EMST=meanwSIM) normio newmopan, ro first
  est store r23
  qui ivreg2 y1 (EMST=meanwSIM) normio newmopan $B $C, ro first
  est store r24
  
  ** Table A7 **
  estout r2*, starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_*) stat(N r2 idstat, fmt(0 3 3))

  
* Controlling for member state variables 

  g lnstates=ln(states_num)
    
  qui reg y1 EMST lnstates states_unga_sd newmopan, ro
  est store r31 
  qui reg y1 EMST lnstates states_unga_sd newmopan $B $C, ro
  est store r32
  qui ivreg2 y1 (EMST=meanwSIM) lnstates states_unga_sd newmopan, ro first
  est store r33
  qui ivreg2 y1 (EMST=meanwSIM) lnstates states_unga_sd newmopan $B $C, ro first
  est store r34
  
  ** Table A8 **
  estout r3*, starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_*) stat(N r2 idstat, fmt(0 3 3))
  
	
* Different lag structure for earmarking share    
  
  qui reg y1 EMLT newmopan, ro 
  est store r41
  qui reg y1 EMLT newmopan $B $C, ro  
  est store r42
  qui ivreg2 y1 (EMLT=meanwSIM) newmopan, ro first
  est store r43
  qui ivreg2 y1 (EMLT=meanwSIM) newmopan $B $C, ro first
  est store r44
  
  ** Table A9 ** 
  estout r4*, starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_*) stat(N r2 idstat, fmt(0 3 3))
	
	
* Alternative measurement of earmarking behaviors 

  g lnproj_lt=ln(nproj_lt)
  g lndon_lt=ln(ndon_lt)

  qui reg y1 lnproj_lt newmopan, ro
  est store r51 
  qui reg y1 lnproj_lt newmopan $B $C, ro
  est store r52
  qui reg y1 lndon_lt newmopan, ro
  est store r53 
  qui reg y1 lndon_lt newmopan $B $C, ro
  est store r54
   
  ** Table A10 **
  estout r5*, starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_*) stat(N r2 idstat, fmt(0 3 3))
  
	
* Remove potentially endogenous MIs from MOPAN score

  qui reg y1n EMST newmopan, ro
  est store r61
  qui reg y1n EMST newmopan $B $C, ro
  est store r62
  qui ivreg2 y1n (EMST=meanwSIM) newmopan, ro first
  est store r63
  qui ivreg2 y1n (EMST=meanwSIM) newmopan $B $C, ro first
  est store r64
  
** Table A11 **
estout r6*, starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_*) stat(N r2 idstat, fmt(0 3 3))
  
	
* Evaluation-year fixed effects (not evaluation-type FE)
  
  qui reg y1 EMST i.year, ro
  est store r71 
  qui reg y1 EMST $B $C i.year, ro
  est store r72
  qui ivreg2 y1 (EMST=meanwSIM) i.year, ro first
  est store r73
  qui ivreg2 y1 (EMST=meanwSIM) i.year $B $C, ro first
  est store r74
   
** Table A12 **
estout r7*, starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_* *year*) stat(N r2 idstat, fmt(0 3 3))
	
	
* Simpler instrument: logged number of sectors in which IO is engaged 
  
  global Cn lnsize fieldshare lnage hqS
  
  qui ivreg2 y1 (EMST=lnsectors) newmopan, ro first
  est store r81
  qui ivreg2 y1 (EMST=lnsectors) newmopan $B $Cn, ro first
  est store r82
  qui ivreg2 y1 (EMLT=lnsectors) newmopan, ro first
  est store r83
  qui ivreg2 y1 (EMLT=lnsectors) newmopan $B $Cn, ro first
  est store r84
  
** Table A13 **
estout r8*, starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_*) stat(N r2 idstat, fmt(0 3 3))


* UNDS data

  qui reg y1 emshareLTb newmopan, ro 
  est store r91
  qui reg y1 emshareLTb newmopan $B $C, ro 
  est store r92
  qui reg y1 emshareLTd newmopan, ro 
  est store r93
  qui reg y1 emshareLTd newmopan $B $C, ro 
  est store r94

** Table A14 **
estout r9*, starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) drop(_*) stat(N r2, fmt(0 3))
    
	